<?php
	session_start();
	require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../model/Service/CustomerService.php';
	require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../model/Context/BaseContext.php';
	require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../model/ServiceResult/ServiceResult.php';
	unset($_SESSION['orderDetail']);
	$totalPrice = 0;
	$totalAmount = 0;
	$totalBartTax = 0;
	$strCurrency = "";
	$context = new BaseContext();
	$result = new ServiceResult();
	$customerServices = new CustomerServices();
	$customer = $customerServices->getCustomerByOid($context, $result, $_SESSION['user']['ID']);
	$curComm = $customer->getCustomerDomain()->getComm();
	$curVAT = 0;
	
	if(isset($_SESSION['VAT']))
	{
		$curVAT = $_SESSION['VAT'];
	}
	$str = '<tr class="gradeX odd">
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td align="center"></td>
			<td align="center"></td>
			<td align="center"></td>
			<td align="right"></td>
			<td align="right"></td>
			<td align="right"></td>
			<td align="center"></td>
			<td align="right"></td>
			<td align="center"></td>
		</tr>';   
    	
   			$res['tbody'] = $str;
   			$totalBartTax = $totalAmount * ($curComm/100);
    		$totalAmountBeforeTax = $totalAmount + $totalBartTax;
			$totalAmountAfterTax = $totalAmountBeforeTax + ($totalAmountBeforeTax * ($curVAT/100));
			$totalAmountAfterTaxFact = $totalAmount + ($totalAmountAfterTax * ($curVAT/100));
			$strTfoot = '<tr class="gradeX odd2">
							<td colspan="7"></td>
							<td align="right" style="border-left: 1px solid #bbb;" >ttl cbm</td>
							<td id="totalCbm" align="right" style="border-right: 1px solid #bbb;">0</td>
							<td align="right" style="border-right: 1px solid #bbb;">0</td>
							<td align="right"></td>
							<td align=center></td>
							<td align=right style="border: 1px solid #bbb;"></td>
							<td></td>
						</tr>';
		    if($curComm > 0)
		    {
			    $strTfoot .= '		<tr class="gradeX odd" style="height: 100px; border-top: 2px dotted #333 ;">
										<td colspan="9" style="vertical-align: middle;">comm commission B-Art '.$curComm.'%</td>                                 
										<td align="right" style="vertical-align: middle;">
				                                    	'.($curComm/100).'
										</td>
										<td align="right" style="vertical-align: middle;">
											'.$totalAmount.'
										</td>
	                                    <td align="center" style="vertical-align: middle;">
		                                    '.
	    										$strCurrency
		                                    .'
	                                    </td>
	                                    <td align="right" style="vertical-align: middle;">
											'.$totalBartTax.'
	                                    </td>
	                                    <td></td>
	                                </tr>';
		    }
		    $strTfoot .= '	        <tr class="gradeX odd1">
	                                	<td colspan="10">Amount Chargeable</td>
	                                	<td align="right">Total -</td>                            
	                                	<td align="center">
	                                		'.
	    										$strCurrency
		                                    .'
		                                </td>
	                                	<td class="total" align=right>
	                                		
	                                    </td>
	                                </tr>
	                                 <tr class="gradeX odd1">
	                                	<td colspan="9"></td>
	                                	<td style="text-align:right;">VAT</td>
	                                	<td style="text-align:right;">'.$curVAT.'%</td>                                	
	                                	<td>-</td>
	                                	<td align="right" style="border:1px solid #bbb ;">'.$totalAmountBeforeTax * ($curVAT/100).'</td>
	                                </tr>
	                                 <tr class="gradeX odd2">
	                                	<td colspan="10"></td>
	                                	<td align="right">Total</td>
	                                	<td align=center>	
	                                		'.
	    										$strCurrency
		                                    .'
	                                	</td>
	                                	<td align=right style="border:1px solid #bbb ;">
	                                		
	                                    </td>
	                                </tr>
	                                                 
	                                <input type="hidden" name="sum'.$strCurrency.'" value="'.$totalAmount.'" >
	                                <input type="hidden" name="sum'.$strCurrency.'Fact" value="'.$totalAmountAfterTaxFact.'" >                 
						';
	$res['tfoot'] = $strTfoot;
    echo json_encode($res);	
?>